#include "GlView.hpp"
#include <GL/gl.h>
#include <GL/glu.h>
using namespace m3g_viewer;


GlView:: GlView (MainView* view) : Fl_Gl_Window(0,40,340,220), main_view(view)
{

}



GlView:: ~GlView ()
{


}

void GlView:: init ()
{
    float width  = w();
    float height = h();

    glClearColor (0,0,1,1);
    glViewport   (0,0,width,height);

    glMatrixMode   (GL_PROJECTION);
    glLoadIdentity ();
    gluPerspective (45, width/(float)height, 0.1, 100);
}

void GlView:: draw ()
{
    if (!valid()) {
        init();
    }
    glClear      (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode   (GL_MODELVIEW);
    glLoadIdentity ();

    gluLookAt (0,2,5,
               0,0,0,
               0,1,0);

    glBegin    (GL_TRIANGLE_STRIP);
    glVertex3f ( 1,0, 1);
    glVertex3f ( 1,0,-1);
    glVertex3f (-1,0, 1);
    glVertex3f (-1,0,-1);
    glEnd      ();
}

